package com.oma.testcase;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

public class Email {

	public void mail(WebDriver driver, String mail){
		driver.manage().window().maximize();
		if(mail == "disapprove")
		{
			driver.findElement(By.xpath("//a[@id='disapproveBtn']")).click();
			
			//Remarks
			driver.findElement(By.xpath("//p[contains(., 'Remarks')]"));
			WebElement remarks = driver.findElement(By.xpath("//div[@id='myModal']/div[2]/form/textarea"));
			remarks.sendKeys("Disapproved by MedSec GC.");
			driver.findElement(By.xpath("//button[contains(., 'Disapprove')]")).click();
			driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
			
			//Confirmation
			driver.findElement(By.xpath("//div[@id='modalError3']/div[3]/button[1]")).click();
			driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
			
			//Approved
			driver.findElement(By.xpath("//div[@id='modalError']/div[3]/button[1]")).click();
			driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
			System.out.println("Disapproved mail sent!");
			
		}
		else if(mail == "defer")
		{
			driver.findElement(By.xpath("//a[@id='deferBtn']")).click();
			
			//Remarks
			driver.findElement(By.xpath("//p[contains(., 'Remarks')]"));
			WebElement remarks = driver.findElement(By.xpath("//div[@id='myModal5']/div[2]/form/textarea"));
			remarks.sendKeys("Defer by MedSec GC.");
			driver.findElement(By.xpath("//button[contains(., 'Defer')]")).click();
			driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
			
			//Confirmation
			driver.findElement(By.xpath("//div[@id='modalError3']/div[3]/button[1]")).click();
			driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
			
			//Insert Notes
			driver.findElement(By.xpath("//b[@id='note1']")).click();
			driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
			WebElement note = driver.findElement(By.xpath("//div[@id='noteModal']/div[2]/textarea"));
			note.sendKeys("JUST A RANDOM STRING");
			driver.findElement(By.xpath("//button[contains(., 'Apply')]")).click();
			driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
			
			//Send Deferred Email
			driver.findElement(By.xpath("//div[@id='deferredModal']/div[3]/button[1]")).click();
			driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
			driver.findElement(By.xpath("//div[@id='modalError']/div[3]/button[1]")).click();
			driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
			System.out.println("Deferred mail sent!");
			
		}
		else if(mail == "approve")
		{
			try{
			//APPLICABLE FOR REVIEWER ONLY!
			driver.findElement(By.xpath("//button[@id='sendEmailBtn']")).click();
			
			//Insert Notes
			driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
			driver.findElement(By.xpath("//b[@id='note4']")).click();
			driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
			WebElement note = driver.findElement(By.xpath("//div[@id='noteModal']/div[2]/textarea"));
			note.sendKeys("JUST A RANDOM STRING");
			driver.findElement(By.xpath("//button[contains(., 'Apply')]")).click();
			driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
			driver.findElement(By.xpath("//b[@id='note5']")).click();
			driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
			WebElement notes = driver.findElement(By.xpath("//div[@id='noteModal']/div[2]/textarea"));
			notes.sendKeys("JUST A RANDOM STRING");
			driver.findElement(By.xpath("//button[contains(., 'Apply')]")).click();
			driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
			
			//Send Approved Mail
			driver.findElement(By.xpath("//div[@id='approvedModal']/div[3]/button[1]")).click();
			driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
			driver.findElement(By.xpath("//div[@id='modalError']/div[3]/button[1]")).click();
			driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
			System.out.println("Approved mail sent!");
			}catch(Exception e){
				System.out.println(e);
			}
		}
		else
		{
			System.out.println("No matched mail category found!");
		}
		System.out.println(driver.findElement(By.xpath("//div[@class='bar bar-alert']")).getText());
	}
	
	
	
}


